
// Copyright (C) Recursion Company. All rights reserved.

#ifndef __VOL_MFC_COLOR_POPUP_H__
#define __VOL_MFC_COLOR_POPUP_H__

#define VCPN_SELCHANGE     WM_USER + 0x6001  // Colour Picker Selection change
#define VCPN_SELENDOK      WM_USER + 0x6002  // Colour Picker end OK
#define VCPN_SELENDCANCEL  WM_USER + 0x6003  // Colour Picker end (cancelled)
#define VCPN_DESTORYED     WM_USER + 0x6004  // Colour Picker destroyed

typedef struct
{
    COLORREF m_clrCurrent;
    UINT64 m_u64UserData;
    INT_P m_npUserData;
}
VOL_CP_SEL_COLOR_INFO;

// To hold the colours and their names
typedef struct
{
    const TCHAR* szName;
    COLORREF crColour;
}
VolColourTableEntry;

class CVolColourPopup : public CWnd
{
public:
    inline_ CVolColourPopup ()
    {
        init ();
    }

    CVolColourPopup (INT x, INT y, COLORREF crInitialColour, CWnd* pParentWnd, const TCHAR* szDefaultColorName,
            COLORREF clrDefault, const TCHAR* szCustomColorName, UINT64 u64UserData, INT_P npUserData);
    ~CVolColourPopup ();

public:
    BOOL Create (INT x, INT y, COLORREF crInitialColour, CWnd* pParentWnd, const TCHAR* szDefaultColorName,
            COLORREF clrDefault, const TCHAR* szCustomColorName, UINT64 u64UserData, INT_P npUserData);

    //{{AFX_VIRTUAL(CVolColourPopup)
    virtual LRESULT WindowProc (UINT message, WPARAM wParam, LPARAM lParam);
    virtual void PostNcDestroy ();
    //}}AFX_VIRTUAL

protected:
    void init ();
    BOOL GetCellRect (INT nIndex, CRect& rect);
    void FindCellFromColour (COLORREF crColour);
    void UpdateWindowPos (INT xRight, INT yTop);
    void CreateToolTips ();
    void ChangeSelection (INT nIndex);
    void EndSelection (INT nMessage);
    void DrawCell (CDC* pDC, INT nIndex);

    inline_ COLORREF GetColour (INT nIndex)  { return m_crColours[nIndex].crColour; }
    inline_ const TCHAR* GetColourName(INT nIndex)  { return m_crColours[nIndex].szName; }
    INT GetIndex (INT row, INT col) const;
    INT GetRow (INT nIndex) const;
    INT GetColumn (INT nIndex) const;

public:
    #define _NUM_COLOUR_TABLE_ENTRIES  32
    static VolColourTableEntry m_crColours [];
    static const TCHAR* sGetColorName (COLORREF clr);

protected:
    INT          m_nNumColours;
    INT          m_nNumColumns, m_nNumRows;
    INT          m_nBoxSize, m_nMargin;
    INT          m_nCurrentSel;
    INT          m_nChosenColourSel;
    CVolString   m_strDefaultColorName;
    COLORREF     m_crDefault;
    CVolString   m_strCustomColorName;
    CRect        m_rtCustomText, m_rtDefaultText, m_rtWindow;
    CFont        m_objFont;
    CPalette     m_objPalette;
    COLORREF     m_crInitialColour, m_crColour;
    CToolTipCtrl m_objToolTip;
    HWND         m_hParentWnd;
    BOOL         m_blHited;
    BOOL         m_blDlgEntried;
    UINT64       m_u64UserData;
    INT_P        m_npUserData;

protected:
    //{{AFX_MSG(CVolColourPopup)
    afx_msg void OnLButtonUp (UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown (UINT nFlags, CPoint point);
    afx_msg void OnPaint ();
    afx_msg void OnMouseMove (UINT nFlags, CPoint point);
    afx_msg void OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg BOOL OnQueryNewPalette ();
    afx_msg void OnPaletteChanged (CWnd* pFocusWnd);
    afx_msg void OnKillFocus (CWnd* pNewWnd);
    afx_msg void OnActivateApp (BOOL bActive, DWORD dwTask);
    afx_msg void OnDestroy ();
    afx_msg BOOL OnSetCursor (CWnd* pWnd, UINT nHitTest, UINT message);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

#endif
